package cn.wolfcode.trip.base.domain;

import cn.wolfcode.trip.base.util.JSONUtil;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import lombok.Getter;
import lombok.Setter;
import org.springframework.format.annotation.DateTimeFormat;

import java.util.Date;
import java.util.HashMap;
import java.util.List;

@Getter
@Setter
@JsonIgnoreProperties({"handler", "json"})
public class StrategyComment extends BaseDomain {
    public static final int STATE_DISABLE = -1;//禁用
    public static final int STATE_NOMAL = 0;//普通
    public static final int STATE_HOT = 1;//推荐
    //用户
    private User user;
    //创建时间
    @JsonFormat(pattern = "y-M-d", timezone = "GMT+8")
    @DateTimeFormat(pattern = "y-M-d")
    private Date createTime;
    //内容
    private String content;
    //图片
    private String imgUrls;
    //多少颗星
    private Integer starNum;
    //所属大攻略
    private Strategy strategy;
    //状态
    private Integer state;
    //推荐时间
    @JsonFormat(pattern = "y-M-d", timezone = "GMT+8")
    @DateTimeFormat(pattern = "y-M-d")
    private Date commendTime;

    private List<Tag> tags;

    private int commentNum;

    public String getJson() {
        HashMap<Object, Object> map = new HashMap<>();
        if (user != null) {
            map.put("user", user);
        }
        if (strategy != null) {
            map.put("strategy", strategy);
        }
        if (tags != tags) {
            map.put("tags", tags);
        }
        map.put("createTime", createTime);
        map.put("id", id);
        map.put("content", content);
        map.put("imgUrls", imgUrls);
        map.put("starNum", starNum);
        map.put("state", state);
        map.put("commendTime", commendTime);

        return JSONUtil.toJSONString(map);
    }
}